//添加论坛文章评论记录并更新评论数
exports.au_forum_content_comment = function (req, res) {

    var bodyParams = req.routeInfo.bodyParams;
    //最终结果
    var resultData = {};

    var forumCommentAnswerData = 0;
    //任务流创建
    async.waterfall([
            //1.添加回答记录
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.addForumContentComment,
                        method: 'POST',
                        data: {
                            fcc_fcid: bodyParams.fcc_fcid,
                            fcc_content: bodyParams.fcc_content,
                            fcc_uid: bodyParams.fcc_uid,
                            fcc_is_reply: bodyParams.fcc_is_reply == undefined ? 0 : bodyParams.fcc_is_reply,
                            fcc_reply_uid: bodyParams.fcc_reply_uid == undefined ? 0 : bodyParams.fcc_reply_uid,
                            fcc_fid: bodyParams.fcc_fid == undefined ? 0 : bodyParams.fcc_fid,
                            fcc_is_author_commnet: bodyParams.fcc_is_author_commnet == undefined ? 0 : bodyParams.fcc_is_author_commnet
                        }
                    },
                    function (err, data) {
                        // //console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }
                        resultData.addData = data.data;
                        cb();
                    }
                );
            },
            //查询评论数量
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.search_question + "/fc_id/" + bodyParams.fcc_fcid,
                        method: 'POST',
                        data: {
                            fields: ["fc_id", "fc_answer_count"].join(",")
                        }
                    },
                    function (err, data) {
                        //console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }

                        forumCommentAnswerData = data.data;
                        cb();
                    }
                );

            },
            //3.论坛文章评论数量更新
            function (cb) {
                if(bodyParams.fcc_is_reply == undefined){
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.updateContent,
                            method: 'POST',
                            data: {
                                fc_id: bodyParams.fcc_fcid,
                                fc_answer_count: parseInt(forumCommentAnswerData[0].fc_answer_count) + 1
                            }
                        },
                        function (err, data) {
                            //判断是否有错误信息
                            if (err) {
                                return RES.response(res, false, data);
                            }

                            resultData.updateData = data;
                            cb();
                        }
                    );
                }else{
                    cb();
                }
            },
        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}